Skip to content

[docs] Templates paths to override in a theme #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hribeir0
Copy link

@hribeir0 hribeir0 commented Aug 1, 2025

Information regarding the final paths depending on the template to override

Copy link

netlify bot commented Aug 1, 2025

Deploy Preview for moodledevdocs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8145276
🔍 Latest deploy log https://app.netlify.com/projects/moodledevdocs/deploys/6899f77a46aa0e000801c70e
😎 Deploy Preview https://deploy-preview-1411--moodledevdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member

@andrewnicols andrewnicols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be backported to versioned_docs/*/docs/guides/templates/index.md.

The version for main should use paths in the public directory, for example public/theme/templates/...

@@ -528,6 +528,22 @@ Templates can be overridden by a theme.
1. Copy the `ratingui.mustache` file into the newly created `theme/timtam/templates/mod_wiki` and edit it.
You should see your changes immediately if theme designer mode is on. Templates are cached just like CSS, so if you are not using theme designer mode you will need to purge all caches to see the latest version of an edited template. If the template you are overriding contains a documentation comment it is recommended to remove it. It will still show the documentation in the template library.

### Paths for overriding templates
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all documented above. The following are examples.

@@ -528,6 +528,22 @@ Templates can be overridden by a theme.
1. Copy the `ratingui.mustache` file into the newly created `theme/timtam/templates/mod_wiki` and edit it.
You should see your changes immediately if theme designer mode is on. Templates are cached just like CSS, so if you are not using theme designer mode you will need to purge all caches to see the latest version of an edited template. If the template you are overriding contains a documentation comment it is recommended to remove it. It will still show the documentation in the template library.

### Paths for overriding templates

#### Overriding a template from another plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generic to all components, not just plugins.

All use their frankenstyle namespace. For an activity that may be mod_example. For a block, block_example. For a core subsystem it's core_[subsystem], and for core itself, it's just core.


#### Overriding a template from another plugin

If you want to override `theme/boost/templates/navbar.mustache`, you should copy and modify it, then **save the new version at** `theme/mytheme/templates/theme_boost/navbar.mustache`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to bold the save the new version.

Give an example here. Be clear. Perhaps use a table.

The example of a template from a theme is the most confusing. Mention it last.

Suggested change
If you want to override `theme/boost/templates/navbar.mustache`, you should copy and modify it, then **save the new version at** `theme/mytheme/templates/theme_boost/navbar.mustache`.
To override a template, you should copy the core template into your theme and then modify the new copy.
Templates are stored in the `templates` directory of your theme.
Within the `theme/[mytheme]/templates` directory the template should be placed in a folder using the frankenstyle name of the component, and then use the same folder and name as the original template within that location.
| Path for original template | Component | Theme override path |
| --- | --- | --- |
| `blocks/myoverview/templates/view-summary.mustache` | `block_myoverview` | `theme/mytheme/templates/block_myoverview/view-summary.mustache` |
| `lib/templates/modal.mustache` | `core` | `theme/mytheme/templates/core/modal.mustache` |
| `theme/boost/templates/navbar.mustache` | `theme_boost` | `theme/mytheme/templates/theme_boost/navbar.mustache` |

Comment on lines +536 to +546

This principle applies to other plugins. For example, to override the template at `blocks/myoverview/templates/view-summary.mustache` you would place your own at `theme/mytheme/templates/block_myoverview/view-summary.mustache`.

#### Overriding a template from lib/

To override a core template, like, `lib/templates/notification_success.mustache:` you should have your own copy at `theme/mytheme/templates/core/notification_success.mustache`.

#### Overriding a core subsystem template

To override a core subsystem template, for example, `message/templates/message_preferences.mustache` place your template at `theme/mytheme/templates/core_message/message_preferences.mustache`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete

Suggested change
This principle applies to other plugins. For example, to override the template at `blocks/myoverview/templates/view-summary.mustache` you would place your own at `theme/mytheme/templates/block_myoverview/view-summary.mustache`.
#### Overriding a template from lib/
To override a core template, like, `lib/templates/notification_success.mustache:` you should have your own copy at `theme/mytheme/templates/core/notification_success.mustache`.
#### Overriding a core subsystem template
To override a core subsystem template, for example, `message/templates/message_preferences.mustache` place your template at `theme/mytheme/templates/core_message/message_preferences.mustache`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants